<?php if ( ! defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );
/**
 * BackendPro
 *
 * A website backend system for developers for PHP 4.3.2 or newer
 *
 * @package         conlabz CMS
 * @author          Christian Schneider
 * @copyright       Copyright (c) 2009
 * @license        
 * @link            http://www.conlabz.de
 * @filesource
 */

// ---------------------------------------------------------------------------

/**
 * Form
 *
 * Create dynamical forms for a website, like contact form
 *
 * @package         conlabz CMS
 * @subpackage      Controllers
 */
class Form extends Public_Controller {
	function Form( ) {
		parent::Public_Controller( );
		
		// Load the blog  model
		$this->load->model( 'form_model' );
		
		// Load the blog module
		$this->lang->module_load( 'form', 'form' );

				
		log_message( 'debug', 'conlabz CMS : Form class loaded on frontend' );
	}	
	
	/**
	 * Mail form information
	 *
	 * @access public
	 */
	function mail( $form_id ) {
		//echo "send mail here";
		//@todo: get information from form informations
		$this->load->library( 'email' );
		
		$result_form = $this->form_model->getForms( "`id` = '".$form_id."'" );
		$row_form = $result_form->result_array( );
		$this->email->from( $row_form[0]['email'], $row_form[0]['title'] );
		$this->email->to( $row_form[0]['email'] );
		
		$this->email->subject( 'Kontaktformular' );
		
		// Get forms
		$result	= $this->form_model->getFormFields( $form_id );
		$row = $result->result_array( );
		$label = unserialize( $row[0]['label'] );
		$name = unserialize( $row[0]['name'] );
		$message = "";
		foreach( $label as $key => $value ){
			if( !empty( $value ) ){
				$message .= $value . ": " . $this->input->post( $name[$key] ) . "<br />";
			}
		}
		
		$this->email->message( $message );
		
		$this->email->send();
		
		redirect( $_SERVER['HTTP_REFERER'], 'refresh' ); 
	}
}
/* End of file blog.php */
/* Location: ./modules/blog/controllers/user/blog.php */